package com.reekr.a5t.web.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.reekr.a5t.model.User;
import com.reekr.a5t.service.UserService;
import com.reekr.a5t.web.annotation.SessionInfo;

@RequestMapping("/index")
@Controller
public class IndexController extends BaseController {
	
	public static String KEY_USER = "user";
	
	@Autowired
	UserService userService;
	
	@RequestMapping(value = "/login.json", method = RequestMethod.GET)
	public void login(HttpSession session,@RequestParam("loginName") String loginName,@RequestParam("loginPass")String loginPass,Model model)
	{
		boolean success = false;
		User user = userService.login(loginName, loginPass);
		if(user!=null)
		{
			success = true;
			user.setLoginPass("");
			session.setAttribute(KEY_USER, user);
			model.addAttribute("user", user);
		}
		model.addAttribute("success", success);
	}

}
